package com.dfiov.cloud.msmtools.aop;

import lombok.extern.slf4j.Slf4j;
import org.aspectj.lang.JoinPoint;
import org.aspectj.lang.annotation.*;
import org.slf4j.MDC;
import org.springframework.stereotype.Component;

import java.util.UUID;

@Aspect
@Component
@Slf4j
public class LoggerAspect {

    @Pointcut("execution(public * com.dfiov.cloud.msmtools.controller..*.*(..))")
    public void log(){}

    @Before("log()")
    public void requestBefore(JoinPoint joinPoint) {
        String uuid = UUID.randomUUID().toString().replace("-", "");
        MDC.put("traceId", uuid);
    }

    @After("log()")
    public void requestAfter(JoinPoint joinPoint) {
        MDC.clear();
    }
}
